home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / c-tools / c_examples / button / rastport.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-16  |  4.6 KB  |  233 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. // rastport.cpp
  3. //
  4. // Jeffry A Worth
  5. // November 10, 1995
  6. //////////////////////////////////////////////////////////////////////////////
  7.  
  8. //////////////////////////////////////////////////////////////////////////////
  9. // INCLUDES
  10. #include "aframe:include/rastport.hpp"
  11.  
  12. //////////////////////////////////////////////////////////////////////////////
  13. //
  14.  
  15. AFRastPort::AFRastPort(AFWindow* pwindow)
  16. {
  17.   if(pwindow) {
  18.     m_prastport = pwindow->m_pWindow->RPort;
  19.     m_pwindow = pwindow->m_pWindow;
  20.   } else
  21.     m_pwindow = NULL;
  22. }
  23.  
  24. AFRastPort::AFRastPort(AFScreen* pscreen)
  25. {
  26.   if(pscreen)
  27.     m_prastport = &(pscreen->m_pScreen->RastPort);
  28. }
  29.  
  30. void AFRastPort::FromWindow(AFWindow* pwindow)
  31. {
  32.   if(pwindow) {  
  33.     m_prastport = pwindow->m_pWindow->RPort;
  34.     m_pwindow = pwindow->m_pWindow;
  35.   }
  36. }
  37.  
  38. void AFRastPort::FromScreen(AFScreen* pscreen)
  39. {
  40.   if(pscreen)
  41.     m_prastport = &(pscreen->m_pScreen->RastPort);
  42. }
  43.  
  44. void AFRastPort::FromHandle(LPWindow pwindow)
  45. {
  46.   if(pwindow) {
  47.     m_prastport = pwindow->RPort;
  48.     m_pwindow = pwindow;
  49.   }
  50. }
  51.  
  52. // Graphics functions
  53.  
  54. void AFRastPort::Clear()
  55. {
  56.   ::ClearScreen(m_prastport);
  57. }
  58.  
  59. void AFRastPort::TextOut(AFPoint* point, AFString* string)
  60. {
  61.     TextOut(point->m_x,point->m_y,string->data(),string->length());
  62. }
  63.  
  64. void AFRastPort::TextOut(ULONG x, ULONG y, char *lpszData, ULONG length)
  65. {
  66.   if(m_prastport) {
  67.     ::Move(m_prastport,x,y);
  68.     ::Text(m_prastport,lpszData,length);
  69.   }
  70. }
  71.  
  72. void AFRastPort::Move(ULONG x, ULONG y)
  73. {
  74.   if(m_prastport) {
  75.     ::Move(m_prastport,x,y);
  76.   }
  77. }
  78.  
  79. void AFRastPort::Move(AFPoint* point)
  80. {
  81.   if(m_prastport) {
  82.     ::Move(m_prastport,point->m_x,point->m_y);
  83.   }
  84. }
  85.  
  86. void AFRastPort::Draw(ULONG x, ULONG y)
  87. {
  88.   if(m_prastport) {
  89.     ::Draw(m_prastport,x,y);
  90.   }
  91. }
  92.  
  93. void AFRastPort::Draw(AFPoint* point)
  94. {
  95.   if(m_prastport) {
  96.     ::Draw(m_prastport,point->m_x,point->m_y);
  97.   }
  98. }
  99.  
  100. void AFRastPort::Text(char *lpszData, ULONG length)
  101. {
  102.   if(m_prastport) {
  103.     ::Text(m_prastport,lpszData,length);
  104.   }
  105. }
  106.  
  107. void AFRastPort::SetAPen(UBYTE pen)
  108. {
  109.   if(m_prastport) {
  110.     ::SetAPen(m_prastport,pen);
  111.   }
  112. }
  113.  
  114. void AFRastPort::SetBPen(UBYTE pen)
  115. {
  116.   if(m_prastport) {
  117.     ::SetBPen(m_prastport,pen);
  118.   }
  119. }
  120.  
  121. void AFRastPort::SetDrMd(ULONG drawmode)
  122. {
  123.   if(m_prastport) {
  124.     ::SetDrMd(m_prastport,drawmode);
  125.   }
  126. }
  127.  
  128. ULONG AFRastPort::GetAPen()
  129. {
  130.   return ::GetAPen(m_prastport);
  131. }
  132.  
  133. ULONG AFRastPort::GetBPen()
  134. {
  135.   return ::GetBPen(m_prastport);
  136. }
  137.  
  138. ULONG AFRastPort::GetDrMd()
  139. {
  140.   return ::GetDrMd(m_prastport);
  141. }
  142.  
  143. void AFRastPort::RectFill(AFRect* prect)
  144. {
  145.   int x1,x2,y1,y2,tmp;
  146.  
  147.   // Get all the coordinates
  148.   x1=prect->TopLeft()->m_x;
  149.   x2=prect->BottomRight()->m_x;
  150.   y1=prect->TopLeft()->m_y;
  151.   y2=prect->BottomRight()->m_y;
  152.  
  153.   // Make sure coordinated go down and to the right
  154.   // This is required by the RectFill function
  155.   if(x1>x2) {
  156.     tmp=x1;x1=x2;x2=tmp;
  157.   }
  158.   if(y1>y2) {
  159.     tmp=y1;y1=y2;y2=tmp;
  160.   }
  161.  
  162.   ::RectFill(m_prastport,x1,y1,x2,y2);
  163. }
  164.  
  165. void AFRastPort::Rect(AFRect* prect)
  166. {
  167.   Move(prect->TopLeft());
  168.   Draw(prect->BottomRight()->m_x,prect->TopLeft()->m_y);
  169.   Draw(prect->BottomRight()->m_x,prect->BottomRight()->m_y);
  170.   Draw(prect->TopLeft()->m_x,prect->BottomRight()->m_y);
  171.   Draw(prect->TopLeft());
  172. }
  173.  
  174. long AFRastPort::TextLength(char *text,long length)
  175. {
  176.   return ::TextLength(m_prastport,text,length);
  177. }
  178.  
  179. void AFRastPort::DrawEllipse(AFRect* rect)
  180. {
  181.   AFPoint point((rect->TopLeft()->m_x+rect->BottomRight()->m_x)/2,(rect->TopLeft()->m_y+rect->BottomRight()->m_y)/2);
  182.   
  183.   DrawEllipse(&point,rect->Width()/2,rect->Height()/2);
  184. }
  185.  
  186. void AFRastPort::DrawEllipse(AFPoint* point, long radius)
  187. {
  188.   DrawEllipse(point,radius,radius);
  189. }
  190.  
  191. void AFRastPort::DrawEllipse(AFPoint* point, long xradius, long yradius)
  192. {
  193.   if( (xradius > 0) && (yradius > 0) )
  194.     ::DrawEllipse(m_prastport,point->m_x,point->m_y,xradius,yradius);
  195. }
  196.  
  197. void AFRastPort::Flood(AFPoint* point, int mode)
  198. {
  199.   // This function at present will not wirk,  it also need to make sure there
  200.   // is a TmpRas structure formed to perform the floodfill before it can actually
  201.   // do the flood fill.
  202.  
  203.   ::Flood(m_prastport,point->m_x,point->m_y,mode);
  204. }
  205.  
  206. void AFRastPort::Flood(AFPoint* point)
  207. {
  208.   Flood(point,0);
  209. }
  210.  
  211. void AFRastPort::TextExtent(char *string, int count, PTEXTEXTENT textextent)
  212. {
  213.   ::TextExtent(m_prastport,string,count,textextent);
  214. }
  215.  
  216. void AFRastPort::AskFont(PTEXTATTR textattr)
  217. {
  218.   ::AskFont(m_prastport,textattr);
  219. }
  220.  
  221. // Feb 28, 1996
  222. void AFRastPort::SetRGB4(struct ViewPort *vp, long index,
  223.                         ULONG red, ULONG blue, ULONG green)
  224. {
  225.   ::SetRGB4(vp,index,red,blue,green);
  226. }
  227.  
  228. void
  229. AFRastPort::DrawImage(AFPoint point, LPImage image)
  230. {
  231.     ::DrawImage(m_prastport,image,point.m_x,point.m_y);
  232. }
  233.